//
//  TFViewController.m
//  New
//
//  Created by 才诗琦 on 16/1/18.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//
#define WIDTH  self.view.frame.size.width
#define HEIGHT   self.view.frame.size.height
#define A     (NSInteger)(self.collectionView.contentOffset.x)/ 375
//#define POSITIONID (int)(self.collectionView.contentOffset.x/375)



#import "TFViewController.h"
#import "SliderView-Prefix.pch"
//签协议
@interface TFViewController ()< PassDelegate, PassValueDelegate, DadaDelegate, NuanxinDelegate,YishuValueDelegate>
@property(nonatomic, retain)NSMutableArray *collecArr;
@property(nonatomic, retain)NSArray *viewNameArray;
@property(nonatomic, retain)UICollectionViewFlowLayout *layout;

@property (nonatomic, retain)NSMutableArray *dataArr;
@property (nonatomic, retain)NSMutableArray *dataArrTwo;

@property(nonatomic, assign)NSInteger i ;

@end

@implementation TFViewController



-(void)dealloc
{
    
    [super dealloc];
    [_collecArr dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.collectionView.backgroundColor = [UIColor whiteColor];

   //scrollView的背景图片
    UIImageView *topShadowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
   [topShadowImageView setImage:[UIImage imageNamed:@"top_background_shadow.png"]];
    [self.view addSubview:topShadowImageView];
    
    //创建scrollView名字数组
    SVTopScrollView *topScrollView = [SVTopScrollView shareInstance];
     topScrollView.nameArray = @[@"头条", @"娱乐", @"哒哒", @"暖心", @"艺术", @"要闻"];
    [self.view addSubview:topScrollView];
    viewNameArray = [topScrollView.nameArray mutableCopy];
    
    //collectionView
    [self createCollectionView];
    //调用button的点击方法
    [topScrollView initWithNameButtons:_collectionView];
   
    }


//#pragma mark-创建collectionView
    - (void)createCollectionView
    {
        //流布局
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //布局设置
#warning 滚动方向
        //水平滚动
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        layout.itemSize = CGSizeMake(WIDTH, HEIGHT - 15 );
        
          //行间距
         layout.minimumLineSpacing = 0;
        
        //创建collectionView
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,45, WIDTH , HEIGHT) collectionViewLayout:layout];
        
        
        _collectionView.backgroundColor = [UIColor clearColor];
        //设置代理人
        self.collectionView.dataSource = self;
        self.collectionView.delegate = self;
       //整页滚动
        self.collectionView.pagingEnabled = YES;
        //添加父视图为self.view
        [self.view addSubview: self.collectionView];
        
        
        
        //注册collectionView的cell
        //头条
       [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell1"];
        //娱乐
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell2"];
        //哒哒
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell3"];
        //暖心
         [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell4"];
        //艺术
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell5"];
    
        //管理内存
//
        [layout release];
        [_collectionView release];
}
//调用结束减速方法实现scrollView偏移
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [self adjustTopScrollViewButton:_collectionView];
    
}
//滚动后修改顶部滚动条
- (void)adjustTopScrollViewButton:(UICollectionView *)collectionView
{
  [[SVTopScrollView shareInstance] setButtonUnSelect];
   [SVTopScrollView shareInstance].scrollViewSelectedChannelID = A +100;
    [[SVTopScrollView shareInstance] setButtonSelect];
    [[SVTopScrollView shareInstance] setScrollViewContentOffset];
    
}
#pragma mark - collectionView的协议实现方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   return viewNameArray.count;
}


//cell 设置
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
//头条页
    if (indexPath.row == 0) {
    UICollectionViewCell *cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell1" forIndexPath:indexPath];
      TuijianViewController *Tuijian = [[TuijianViewController alloc] init] ;
    //设置代理人
        Tuijian.delegate = self;
        //接收tableView
        UITableView *tj = [Tuijian setWithUrlStr:@"http://c.3g.163.com/nc/article/list/T1429173683626/0-20.html"];
        
        
        
        [cell1 addSubview:tj];
       
     return cell1 ;
        
    }
    //娱乐页
    if (indexPath.row == 1) {
        UICollectionViewCell *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell2" forIndexPath:indexPath];
        YuleViewController *yuLe = [[YuleViewController alloc] init];
        yuLe.delegate = self;
        
        
        UITableView *yl = [yuLe setWithUrlStr:@"http://c.3g.163.com/nc/article/list/T1348648517839/0-20.html"];
        [cell2 addSubview:yl];
        
      
       return cell2 ;
        }
   //哒哒
    if (indexPath.row == 2) {
         UICollectionViewCell *cell3 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell3" forIndexPath:indexPath];
        DadaViewController *dada = [[DadaViewController alloc] init];
        //设置代理人
        dada.delegate = self;
        UITableView *dd = [dada setWithUrlStr:@"http://c.3g.163.com/nc/article/list/T1444289532601/0-20.html"];
       [cell3 addSubview:dd];
      
        return cell3 ;}
 //暖心
    if (indexPath.row == 3) {
  

    
      UICollectionViewCell *cell4 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell4" forIndexPath:indexPath];
        NuanxinViewController *nuanxin = [[NuanxinViewController alloc] init];
        
        //设置代理人
        nuanxin.delegate = self;
        UITableView *nx = [nuanxin setWithUrl:@"http://api.iclient.ifeng.com/ClientNews?id=NXWPD,FOCUSNXWPD&page=0&gv=4.6.9&av=0&proid=ifengnews&os=ios_8.4.1&vt=5&screen=750x1334&publishid=4002&uid=8e6e52d1d80716f49a4d94ed0c4c60e43a8c37da"];
        
        [cell4 addSubview:nx];
               cell4.tag = 400;
        return cell4;
    
    
    }
    
    else
    {
        
        
            UICollectionViewCell *cell5 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell5" forIndexPath:indexPath];
           YishuVC *yishu = [[YishuVC alloc] init];
            
            //设置代理人
            yishu.delegate = self;
            UITableView *ys = [yishu setWithUrlStr:@"http://c.m.163.com/nc/article/list/T1441074311424/0-20.html"];
            
            [cell5 addSubview:ys];
        
            return cell5;
            
            
        
    }
    
    
   #if 0
      //直播
    #endif
//     else{
//         
//         UICollectionViewCell *cell5 = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell5" forIndexPath:indexPath];
//         ZhiboViewController *zhibo = [[ZhiboViewController alloc] init];
//         UITableView *zb = [zhibo setWithUrl:@"http://api.iclient.ifeng.com/ClientNews?id=ZBPD&gv=4.6.9&av=0&proid=ifengnews&os=ios_8.4.1&vt=5&screen=750x1334&publishid=4002&uid=8e6e52d1d80716f49a4d94ed0c4c60e43a8c37da"];
//         
//         [cell5 addSubview:zb];
//         
//         return cell5;
//         
//         
//    }
    

    
    }

- (void)passValueYishu:(NSString *)url
{
   YishuXiangqingVC  *xiang = [[YishuXiangqingVC alloc] init];
    
    xiang.str = url;
    [self.navigationController pushViewController:xiang animated:YES];
    
}

- (void)NuanxinValue:(NSString *)url
{
    NuanxinXiangqingVC *nuan = [[NuanxinXiangqingVC alloc] init];
    nuan.str = url;
    [self.navigationController pushViewController:nuan animated:YES];
}

- (void)DadaValue:(NSString *)url
{

    DadaXiangqinVC *da = [[DadaXiangqinVC alloc] init];
    da.str = url;
    [self.navigationController pushViewController:da animated:YES];
}



- (void)passValue:(NSString *)url
{
    XiangqingVC *xiang = [[XiangqingVC alloc] init];
    
    xiang.str = url;
    [self.navigationController pushViewController:xiang animated:YES];
    
}

- (void)pass:(NSString *)url 
{
    
    
    XiangqingViewController *xiangQing = [[XiangqingViewController alloc] init];
    xiangQing.str = url;
   
    
    [self.navigationController pushViewController:xiangQing animated:YES];
    
    
}
- (void)dataHandle
{
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
